<?php
/**
 * Created by PhpStorm.
 * User: cscjj2008
 * Date: 14-11-26
 * Time: 下午2:03
 */
class SentrySeeder extends Seeder {

    public function run()
    {
        DB::table('users')->delete();
        DB::table('groups')->delete();
        DB::table('users_groups')->delete();

        Sentry::getUserProvider()->create(array(
            'email'      => 'oo@xx.com',
            'username'   => 'admin',
            'password'   => "ooxx",
            'first_name' => 'OO',
            'last_name'  => 'XX',
            'activated'  => 1,
        ));

        Sentry::getGroupProvider()->create(array(
            'name'        => 'Admin',
            'permissions' => ['admin' => 1],
        ));

        // 将用户加入用户组
        $adminUser  = Sentry::getUserProvider()->findByLogin('oo@xx.com');
        $adminGroup = Sentry::getGroupProvider()->findByName('Admin');
        $adminUser->addGroup($adminGroup);


        Sentry::getUserProvider()->create(array(
            'email'      => 'city@11.com',
            'username'   => 'city',
            'password'   => "ooxx",
            'first_name' => 'ci',
            'last_name'  => 'ty',
            'activated'  => 1,
        ));

        Sentry::getGroupProvider()->create(array(
            'name'        => 'City',
            'permissions' => ['city' => 1],
        ));

        // 将用户加入用户组
        $adminUser  = Sentry::getUserProvider()->findByLogin('city@11.com');
        $adminGroup = Sentry::getGroupProvider()->findByName('City');
        $adminUser->addGroup($adminGroup);


        Sentry::getUserProvider()->create(array(
            'email'      => 'section@11.com',
            'username'   => 'section',
            'password'   => "ooxx",
            'first_name' => 'section',
            'last_name'  => 'section',
            'activated'  => 1,
        ));

        Sentry::getGroupProvider()->create(array(
            'name'        => 'Section',
            'permissions' => ['section' => 1],
        ));

        // 将用户加入用户组
        $adminUser  = Sentry::getUserProvider()->findByLogin('section@11.com');
        $adminGroup = Sentry::getGroupProvider()->findByName('Section');
        $adminUser->addGroup($adminGroup);
    }
}